package com.css.zfzx.sjcj.modules.qhcriteriaqueries.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.bpm.platform.utils.PlatformPageUtils;
import com.css.zfzx.sjcj.modules.qhcriteriaqueries.service.QhCriteriaQueriesService;
import com.css.zfzx.sjcj.modules.qhdrilloverview.viewobjects.QhDrillOverviewQueryParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author tao
 * @date 2020-11-14
 */
@Slf4j
@RestController
@RequestMapping("/qh/zfzxCriteriaQueries")
public class QhCriteriaQueriesController {
    @Autowired
    private QhCriteriaQueriesService qhCriteriaQueriesService;

    /**
     * 导出
     * @param ids
     */
    @GetMapping("/exportFile/{ids}")
    public RestResponse exportExcel(@PathVariable String ids, HttpServletResponse response) {
        RestResponse restResponse = null;
        try {
            String s = qhCriteriaQueriesService.exportExcel(ids, response);
            restResponse = RestResponse.succeed(s);
        } catch (Exception e) {
            String errorMsg = "导出失败!";
            log.error(errorMsg, e);
            restResponse = RestResponse.fail(errorMsg);
        }
        return restResponse;
    }

    /**
     * 导入
     *
     */
    @PostMapping("/importFile")
    public RestResponse importExcel(@RequestParam("files") MultipartFile[] files,HttpServletRequest request) {
        RestResponse restResponse = null;
        try {
            String s = qhCriteriaQueriesService.importExcel(files);
            restResponse = RestResponse.succeed(s);
        } catch (Exception e) {
            String errorMsg = "导入失败!";
            log.error(errorMsg, e);
            restResponse = RestResponse.fail(errorMsg);
        }
        return restResponse;
    }

    /**
     * 系统质检
     */
    @PostMapping("/dataQualityCheck")
    public RestResponse dataQualityCheck(@RequestBody QhDrillOverviewQueryParams queryParams){
        RestResponse restResponse = null;
        try {
            JSONObject jsonObject = qhCriteriaQueriesService.dataQualityCheck(queryParams);
            restResponse = RestResponse.succeed(jsonObject);
        } catch (Exception e) {
            String errorMsg = "质检失败!";
            log.error(errorMsg, e);
            restResponse = RestResponse.fail(errorMsg);
        }
        return restResponse;
    }

    /**
     * 获取是否终检员
     */
    @GetMapping("/isUltimateQc")
    public RestResponse isUltimateQc(HttpServletResponse response) {
        RestResponse restResponse = null;
        try {
            String s = qhCriteriaQueriesService.isUltimateQc();
            restResponse = RestResponse.succeed(s);
        } catch (Exception e) {
            String errorMsg = "无法判断用户角色类型!";
            log.error(errorMsg, e);
            restResponse = RestResponse.fail(errorMsg);
        }
        return restResponse;
    }
}
